package vip.aster.system.entity;

import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.collection.ListUtil;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import lombok.EqualsAndHashCode;
import vip.aster.common.entity.DictData;
import vip.aster.framework.mybatis.entity.BaseEntity;

import java.io.Serial;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

/**
 * 字典数据
 *
 * @author Aster
 * @since 2023-11-28
 */
@Data
@EqualsAndHashCode(callSuper = false)
@TableName("sys_dict_data")
@Schema(description = "字典数据")
public class SysDictData extends BaseEntity<SysDictData> {

    @Serial
    private static final long serialVersionUID = 3582567259110869687L;

    @Schema(description = "ID")
    @TableId("id")
    private String id;

    @Schema(description = "字典类型ID")
    @TableField("dict_type_id")
    private String dictTypeId;

    @Schema(description = "字典标签")
    @TableField("dict_label")
    private String dictLabel;

    @Schema(description = "字典值")
    @TableField("dict_value")
    private String dictValue;

    @Schema(description = "标签样式")
    @TableField("label_class")
    private String labelClass;

    @Schema(description = "排序")
    @TableField("sort")
    private Integer sort;

    @Schema(description = "租户ID")
    @TableField("tenant_id")
    private String tenantId;

    @Schema(description = "启用状态")
    @TableField("status")
    private String status;

    @Schema(description = "备注信息")
    @TableField("remark")
    private String remark;

    @Override
    public Serializable pkVal() {
        return this.id;
    }

    public SysDictData() {
        super();
    }

    public SysDictData(DictData dictData) {
        this.id = dictData.getId();
        this.dictTypeId = dictData.getDictTypeId();
        this.dictLabel = dictData.getDictLabel();
        this.dictValue = dictData.getDictValue();
        this.labelClass = dictData.getLabelClass();
        this.sort = dictData.getSort();
        this.status = dictData.getStatus();
        this.remark = dictData.getRemark();
        this.tenantId = dictData.getTenantId();
    }

    public static DictData convert(SysDictData sysDictData) {
        DictData dictData = new DictData();
        dictData.setId(sysDictData.getId());
        dictData.setDictTypeId(sysDictData.getDictTypeId());
        dictData.setDictLabel(sysDictData.getDictLabel());
        dictData.setDictValue(sysDictData.getDictValue());
        dictData.setLabelClass(sysDictData.getLabelClass());
        dictData.setSort(sysDictData.getSort());
        dictData.setStatus(sysDictData.getStatus());
        dictData.setRemark(sysDictData.getRemark());
        dictData.setTenantId(sysDictData.getTenantId());
        return dictData;
    }

    public static List<DictData> convertList(List<SysDictData> source) {
        if (CollUtil.isEmpty(source)) {
            return ListUtil.empty();
        }
        List<DictData> list = new ArrayList<>();
        for (SysDictData data : source) {
            list.add(convert(data));
        }
        return list;
    }
}
